allele <- c("A", "a")
freq <- c(.9, .1)
#chrom <- 2 * 46

n <- 1000
generation <- 1

plot(freq[1]/sum(freq), xlim=c(1,1000))

while(T)
{
	generation = generation + 1
	# diploid
	pool <- c(rep(allele[1], 2 * n * freq[1]), rep(allele[2], 2 * n * freq[2]))
	freq.old <- freq
	freq <- double(2)
	for(i in 1:n)
	{
		# random sampling
		indiv.new <- sample(pool, 2, replace=T)
		freq[1] = freq[1] + sum(which(indiv.new=="A"))
		freq[2] = freq[2] + sum(which(indiv.new=="a"))
	}
	print(freq / sum(freq))

	if(abs(log10(freq[1]/freq[2])) >= 6)
	{
		break
	}
	#
	lines(c(generation-1, generation),
		c(freq.old[1]/sum(freq.old), freq[1]/sum(freq)))
}
print(generation) # log->208, log10->?

